home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / miscfuncs.abl < prev    next >
Encoding:
Text File  |  2001-07-16  |  12.7 KB  |  516 lines

  1. library mwfunc;
  2.  
  3. const
  4.  
  5. #include_ "mwconst.abi"
  6.  
  7. type
  8. #include_ "mwtype.abi"
  9.  
  10. var
  11.     static ObjectID last_sound_played;
  12.     static Boolean any_sounds_played;
  13.     
  14. //------------------------------------------------------------------------------------
  15.  
  16. function init;
  17.     code
  18.     any_sounds_played = FALSE;
  19.  
  20.         
  21. endfunction;
  22.  
  23.  
  24. function getRelativeAlignment (ObjectID p1,ObjectID p2) : integer;
  25.  
  26.     var
  27.  
  28.         integer align1;
  29.         integer align2;
  30.  
  31.     code
  32.         align1 = getAlignment (p1);
  33.         align2 = getAlignment (p2);
  34.         
  35.         if align2 == NEUTRAL_ALIGNMENT then
  36.             return (NEUTRAL);
  37.         endif;
  38.         if align1 <> align2 then
  39.             return (ENEMY);
  40.         endif;
  41.         return (FRIENDLY);
  42.         
  43. endfunction;
  44.  
  45. function SnapToGround(ObjectID obj);
  46.     var
  47.         LocPoint l;
  48.         
  49.     code
  50.         getLocation(obj,l);
  51.         l[1] = -1;
  52.         teleport(obj,l);
  53. endfunction;
  54.       
  55. function ProtectAGroup(integer group_num) : integer;
  56.     // This one may or may not work. Needs testing.
  57.     var
  58.         
  59.     code
  60.     
  61.     if (isShot (GroupObjectId(group_num))) then
  62.           if (getRelativeAlignment(me,WhoShot(GroupObjectId(group_num))) == ENEMY) then
  63.                 setTarget(me,WhoShot(GroupObjectId(group_num)));
  64.                 return (1);
  65.             endif;
  66.         endif;
  67.         
  68.         return (0);
  69. endfunction;
  70.  
  71.  
  72. function GeneralPlayChatter(ObjectId sound,
  73.  integer which_timer, integer what_delay, integer what_chance);
  74. // if Timer which_timer is over what_delay, there is a chance what_chance
  75. // that the sound sound is played. After this, the timer is reset.    
  76. // use this function for easy handling of radio chatter.
  77. // what_chance is a number from 0 to 1000. The percentage chance of the sound playing is
  78. // what_chance / 10     
  79.     var
  80.     
  81.     code
  82.         if (any_sounds_played == TRUE) then
  83.             if (last_sound_played == sound) then
  84.                 what_chance = -1;
  85.             endif;
  86.         endif;
  87.         
  88.         if (TimeGreater(which_timer,what_delay)) then
  89.             if (Rand(0,1000) <= what_chance) then
  90.                 PlaySound(sound);
  91.                 last_sound_played = sound;
  92.                 any_sounds_played = TRUE;
  93.                 ResetTimer(which_timer);        
  94.             endif;
  95.             
  96.         endif;
  97. endfunction;
  98.  
  99. function SetMyTarget(integer searchrange) : boolean;
  100.     
  101.     var
  102.     
  103.  integer    foe;
  104.       
  105.     code
  106.         foe = FindObject(ME,FA_ENEMY,FT_DEFAULT,FC_BEST_TARGET,FF_WHO_SHOT + FF_SEEPLAYER,searchrange);
  107.         
  108.         if (foe <> no_unit) then
  109.             SetTarget (me,foe);
  110.             return (true);
  111.         endif;
  112.  
  113.         return (false);
  114.                 
  115. endfunction;
  116.  
  117. function FindEnemy(integer searchrange, integer flags) : boolean;
  118.     
  119.     var
  120.         integer foe;
  121.       
  122.     code
  123.         foe = FindObject(ME,FA_ENEMY,flags,FC_BEST_TARGET,FF_WHO_SHOT + FF_SEEPLAYER,searchrange);
  124.         
  125.         if (foe <> no_unit) then
  126.             SetTarget (me,foe);
  127.             return (true);
  128.         endif;
  129.  
  130.         return (false);
  131.                 
  132. endfunction;
  133.  
  134. function Bot_FindEnemy(integer searchrange) : boolean;
  135.     
  136.     var
  137.         integer foe;
  138.       
  139.     code
  140.         foe = FindObject(ME,FA_ENEMY,FT_DEFAULT,FC_BEST_TARGET,FF_WHO_SHOT + FF_SEEPLAYER + FF_LOOK_EVERYWHERE,searchrange);
  141.         
  142.         if (foe <> no_unit) then
  143.             SetTarget (me,foe);
  144.             return (true);
  145.         endif;
  146.  
  147.         return (false);
  148.                 
  149. endfunction;
  150.  
  151. function LeaveAttackState(integer withdrawrange) : boolean;
  152.     
  153.     var
  154.     
  155.      integer    target;
  156.       
  157.     code
  158.  
  159.          target = gettarget(me);
  160.  
  161.          //1.  I somehow got here without a legitimate target
  162.         if (target < 0) then
  163.                 return(true);
  164.             else
  165.         //2.  My target is dead            
  166.             if (isDead (target) == TRUE) then
  167.                 return(true);
  168.             else
  169.                 //3.  My target has gotten too far from me
  170.                 if ((isWithin(target,me,withdrawrange)) == FALSE) then
  171.                     if (WhoShot(me) <> target) then
  172.                         return(true);
  173.                     endif;
  174.                 endif;
  175.             endif;
  176.         endif;
  177.  
  178.  
  179.         return (false);
  180.                 
  181. endfunction;
  182.  
  183.  
  184.  
  185. function PlayChatter(ObjectID who_speaks, ObjectId sound,
  186.  integer which_timer, integer what_delay, integer what_chance, Boolean check_combat);
  187. // if Timer which_timer is over what_delay and unit who_speaks is
  188. // alive, there is a chance what_chance
  189. // that the sound sound is played. After this, the timer is reset.    
  190. // If check_combat is TRUE, the sound is only played if who_speaks is involved in a fight.
  191. // use this function for easy handling of radio chatter.     
  192. // what_chance is a number from 0 to 1000. The percentage chance of the sound playing is
  193. // what_chance / 10     
  194.     var
  195.     
  196.     code
  197.         if (any_sounds_played == TRUE) then
  198.             if (last_sound_played == sound) then
  199.                 what_chance = -1;
  200.             endif;
  201.         endif;
  202.         
  203.         
  204.         if ((IsDead(who_speaks) == FALSE) and (TimeGreater(which_timer,what_delay))) then
  205.             if  (Rand(0,1000) <= what_chance) then
  206.                 if ((check_combat == FALSE) or
  207.                 ((check_combat == TRUE) and (IsShot(who_speaks)))) then
  208.                     PlaySound(sound);
  209.                  last_sound_played = sound;
  210.                     any_sounds_played = TRUE;
  211.                     ResetTimer(which_timer);        
  212.                 endif;
  213.             endif;
  214.         endif;
  215. endfunction;
  216.  
  217.  
  218. function GroupPlayChatter(integer group_who_speaks, ObjectId sound,
  219.  integer which_timer, integer what_delay, integer what_chance, Boolean check_combat);
  220.     // if Timer which_timer is over what_delay and group group_who_speaks is
  221. // alive, there is a chance what_chance
  222. // that the sound sound is played. After this, the timer is reset.    
  223. // If check_combat is TRUE, the sound is only played if the group is involved in a fight.
  224. // use this function for easy handling of radio chatter.     
  225. // what_chance is a number from 0 to 1000. The percentage chance of the sound playing is
  226. // what_chance / 10     
  227.     var
  228.     
  229.     code
  230.         if (any_sounds_played == TRUE) then
  231.             if (last_sound_played == sound) then
  232.                 what_chance = -1;
  233.             endif;
  234.         endif;
  235.         
  236.         
  237.         if ((GroupAllDead(GroupObjectId(group_who_speaks)) == FALSE) and (TimeGreater(which_timer,what_delay))
  238.          and (Rand(0,1000) <= what_chance)) then
  239.             if ((check_combat == FALSE) or
  240.             ((check_combat == TRUE) and (IsShot(GroupObjectId(group_who_speaks))))) then
  241.                 PlaySound(sound);
  242.                 last_sound_played = sound;
  243.                 any_sounds_played = TRUE;
  244.                 ResetTimer(which_timer);        
  245.             endif;
  246.         endif;
  247.         
  248. endfunction;
  249.  
  250.  
  251. // Cinema_ZoomOut():
  252. // Does a generic zoom-out camera animation suitable for mission victory or failure cut scenes.
  253. // "who" is the unit to zoom out from; it must be a single unit (typically the player's 'Mech).
  254. // "unique_timer_id" is the ID of a timer that the function can use that's not used for anything
  255. // else in any of the ABL scripts related to this mission.
  256. // "duration" is how long the zoom-out sequence will last.  10 to 20 seconds is generally
  257. // recommended, though this may be anything above 0.  Since the distance to zoom out
  258. // is fixed, a longer duration will mean a slower zoom-out.
  259.  
  260. function Cinema_ZoomOut(ObjectID who, integer unique_timer_id, real duration) : Boolean;
  261.     var
  262.         real time_remaining;
  263.  
  264.     code
  265.         if (Not TimeGreater(unique_timer_id,0)) then
  266.             StartTimer(unique_timer_id);
  267.  
  268.             Targetfollowobject(who);
  269.             camerafollowobject(who);
  270.             SetCameraFootShake(who,100);
  271.  
  272.             TargetOffset(0.0,5.0,0.0,0.0,true);
  273.             CameraOffset(0.0,5.0,30.0,0.0,true);
  274.  
  275.             return (false);
  276.         endif;
  277.  
  278.         if (TimeGreater(unique_timer_id,duration)) then
  279.             return (true);
  280.         endif;
  281.  
  282.         if (duration > 2.0) then
  283.             if (TimeGreater(unique_timer_id,2.0)) then
  284.                 time_remaining = duration - 2.0;
  285.                 TargetOffset(0.0,9.0,-20.0,time_remaining,true);
  286.                 CameraOffset(0.0,40.0,150.0,time_remaining,true);
  287.             endif;
  288.         endif;
  289.  
  290.         return (false);
  291. endfunction;
  292.  
  293.  
  294. // IsShotOrDead():
  295. // Returns true if the unit was shot recently or is destroyed.
  296.  
  297. function IsShotOrDead(ObjectID who) : Boolean;
  298.     var
  299.  
  300.     code
  301.         if (IsDead(who)) then
  302.             return (true);
  303.         endif;
  304.  
  305.         return (IsShot(who));
  306. endfunction;
  307.  
  308.  
  309. // WhoShotOrKilled():
  310. // Indicates who shot or destroyed a given unit
  311.  
  312. function WhoShotOrKilled(ObjectID who) : ObjectID;
  313.     var
  314.     
  315.     code
  316.         if (IsDead(who)) then
  317.             return (WhoDestroyed(who));
  318.         endif;
  319.  
  320.         if (IsShot(who) == false) then
  321.             return (WhoShot(who));
  322.         endif;
  323.  
  324.         return (NO_UNIT);
  325. endfunction;
  326.  
  327.  
  328. // ReachedNav():
  329. // Indicates whether a unit (or group or team) IsWithin() a nav point
  330.  
  331. function ReachedNav(ObjectID who, ObjectID nav) : Boolean;
  332.     var
  333.  
  334.     code
  335.         return (IsWithin(who,nav,150));
  336.  
  337. endfunction;
  338.  
  339.  
  340. function AddStandardBuckets;
  341.     var
  342.  
  343.     code
  344.         TrackBucket(Bucket_KILLS,0,true);
  345.         TrackBucket(Bucket_DEATHS,0,true);
  346.  
  347.         TrackBucket(Bucket_CUSTOM,0,true);
  348. endfunction;
  349.  
  350. function SetupScoring_Attrition;
  351.     var
  352.  
  353.     code
  354.         SetFlagsEnabled(FLAGS_HIDE);
  355.         SetCustomBucketNameIndex(843);
  356.         AddStandardBuckets;
  357.         AddCustomBucketParameter(Bucket_ENEMY_DAMAGE_INFLICT,1);
  358.         AddCustomBucketParameter(Bucket_FRIENDLY_DAMAGE_INFLICT,-1);
  359.         AddCustomBucketParameter(Bucket_ENEMY_KILLS,500);
  360.         AddCustomBucketParameter(Bucket_FRIENDLY_KILLS,-500);
  361.         AddCustomBucketParameter(Bucket_SUICIDES,-1500);
  362.         AddCustomBucketParameter(Bucket_ENEMY_KILLS_BY_TONNAGE,5);
  363.         AddCustomBucketParameter(Bucket_ENEMY_COMPONENT_KILLS,50);
  364.         AddCustomBucketParameter(Bucket_FRIENDLY_COMPONENT_KILLS,-50);
  365. endfunction;
  366.  
  367. function SetupScoring_TeamAttrition;
  368.     var
  369.     
  370.     code
  371.         SetFlagsEnabled(FLAGS_HIDE);
  372.         SetCustomBucketNameIndex(844);
  373.         AddStandardBuckets;
  374.         AddCustomBucketParameter(Bucket_ENEMY_DAMAGE_INFLICT,1);
  375.         AddCustomBucketParameter(Bucket_FRIENDLY_DAMAGE_INFLICT,-1);
  376.         AddCustomBucketParameter(Bucket_ENEMY_KILLS,500);
  377.         AddCustomBucketParameter(Bucket_FRIENDLY_KILLS,-500);
  378.         AddCustomBucketParameter(Bucket_SUICIDES,-1500);
  379.         AddCustomBucketParameter(Bucket_ENEMY_KILLS_BY_TONNAGE,5);
  380.         AddCustomBucketParameter(Bucket_ENEMY_COMPONENT_KILLS,50);
  381.         AddCustomBucketParameter(Bucket_FRIENDLY_COMPONENT_KILLS,-50);
  382. endfunction;
  383.  
  384. function SetupScoring_Destruction;
  385.     var
  386.  
  387.     code
  388.         SetFlagsEnabled(FLAGS_HIDE);
  389.         SetCustomBucketNameIndex(845);
  390.         AddStandardBuckets;
  391.         AddCustomBucketParameter(Bucket_KILLS,1);
  392.         AddCustomBucketParameter(Bucket_SUICIDES,-2);
  393. endfunction;
  394.  
  395. function SetupScoring_TeamDestruction;
  396.     var
  397.  
  398.     code
  399.         SetFlagsEnabled(FLAGS_HIDE);
  400.         SetCustomBucketNameIndex(846);
  401.         AddStandardBuckets;
  402.         AddCustomBucketParameter(Bucket_ENEMY_KILLS,1);
  403.         AddCustomBucketParameter(Bucket_FRIENDLY_KILLS,-1);
  404.         AddCustomBucketParameter(Bucket_SUICIDES,-1);
  405. endfunction;
  406.  
  407. function SetupScoring_STB;
  408.     var
  409.  
  410.     code
  411.         SetFlagsEnabled(FLAGS_UNIVERSAL_ONLY);
  412.         SetFlagCaptureEnabled(false);
  413.         ShowFlagsAsNavPoints(TRUE);
  414.         SetCustomBucketNameIndex(850);
  415.         AddStandardBuckets;
  416.         AddCustomBucketParameter(Bucket_FLAG_HOLD_TIME,1);
  417. endfunction;
  418.  
  419. function SetupScoring_KOTH(ObjectID hill, integer radius);
  420.     var
  421.  
  422.     code
  423.         SetFlagsEnabled(FLAGS_HIDE);
  424.         if (hill <> -1) then
  425.             TrackObjectBucket(Bucket_OBJECTIVE_CONTESTED,hill,radius,false);
  426.             TrackObjectBucket(Bucket_OBJECTIVE_UNCONTESTED,hill,radius,false);
  427.         endif;
  428.         SetCustomBucketNameIndex(848);
  429.         AddStandardBuckets;
  430.         AddCustomBucketParameter(Bucket_OBJECTIVE_CONTESTED,1);
  431.         AddCustomBucketParameter(Bucket_OBJECTIVE_UNCONTESTED,5);
  432. endfunction;
  433.  
  434. function SetupScoring_TKOTH(ObjectID hill, integer radius);
  435.     var
  436.  
  437.     code
  438.         SetFlagsEnabled(FLAGS_HIDE);
  439.         if (hill <> -1) then
  440.             TrackObjectBucket(Bucket_OBJECTIVE_CONTESTED,hill,radius,false);
  441.             TrackObjectBucket(Bucket_OBJECTIVE_UNCONTESTED,hill,radius,false);
  442.         endif;
  443.         SetCustomBucketNameIndex(849);
  444.         AddStandardBuckets;
  445.         AddCustomBucketParameter(Bucket_OBJECTIVE_CONTESTED,1);
  446.         AddCustomBucketParameter(Bucket_OBJECTIVE_UNCONTESTED,5);
  447. endfunction;
  448.  
  449. function SetupScoring_CTF;
  450.     var
  451.  
  452.     code
  453.         SetFlagsEnabled(FLAGS_TEAM_ONLY);
  454.         ShowFlagsAsNavPoints(TRUE);
  455.         SetCustomBucketNameIndex(847);
  456.         AddStandardBuckets;
  457.         AddCustomBucketParameter(Bucket_FLAGS_CAPTURED,1000);
  458.         AddCustomBucketParameter(Bucket_ENEMY_KILLS,25);
  459.         AddCustomBucketParameter(Bucket_FRIENDLY_KILLS,-50);
  460. endfunction;
  461.  
  462. function SetupScoring_Territories(ObjectID hill, integer radius);
  463.     var
  464.  
  465.     code
  466.         SetFlagsEnabled(FLAGS_HIDE);
  467.         if (hill <> -1) then
  468.             TrackObjectBucket(Bucket_OBJECTIVE_UNCONTESTED,hill,radius,false);
  469.         endif;
  470.         SetCustomBucketNameIndex(852);
  471.         AddStandardBuckets;
  472.         AddCustomBucketParameter(Bucket_OBJECTIVE_UNCONTESTED,1);
  473. endfunction;
  474.  
  475. function SetupScoring_CaptureBase;
  476.     var
  477.  
  478.     code
  479.         SetFlagsEnabled(FLAGS_HIDE);
  480.         SetCustomBucketNameIndex(853);
  481.         AddStandardBuckets;
  482.         AddCustomBucketParameter(Bucket_ENEMY_KILLS,25);
  483.         AddCustomBucketParameter(Bucket_FRIENDLY_KILLS,-50);
  484. endfunction;
  485.  
  486. function SetupScoring_DestroyObjective;
  487.     var
  488.  
  489.     code
  490.         SetFlagsEnabled(FLAGS_HIDE);
  491.         SetCustomBucketNameIndex(854);
  492.         AddStandardBuckets;
  493.         // TODO: add scoring for objective destruction
  494.         AddCustomBucketParameter(Bucket_ENEMY_KILLS,25);
  495.         AddCustomBucketParameter(Bucket_FRIENDLY_KILLS,-50);
  496. endfunction;
  497.  
  498. function SetupScoring_Escort;
  499.     var
  500.  
  501.     code
  502.         SetFlagsEnabled(FLAGS_HIDE);
  503.         SetCustomBucketNameIndex(851);
  504.         AddStandardBuckets;
  505.         AddCustomBucketParameter(Bucket_ENEMY_KILLS,500);
  506.         AddCustomBucketParameter(Bucket_FRIENDLY_KILLS,-500);
  507. endfunction;
  508.  
  509.  
  510. code
  511.  
  512.     print("mwfunc");
  513.  
  514. endlibrary.
  515.  
  516.